package com.czy.owner.ui.coupons;


import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;

import com.czy.owner.R;
import com.czy.owner.adapter.CommonTabLayoutAdapter;
import com.czy.owner.ui.BaseActivity;
import com.czy.owner.ui.BaseFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;


/**
 * Created by wangyang on 2017/4/13 0013.
 * 优惠券
 */
public class CouponsActivity extends BaseActivity {
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    @BindView(R.id.tabs)
    TabLayout mTabLayout;
    private List<String> titles;
    private CommonTabLayoutAdapter mFragmentAdapter;
    private List<BaseFragment> mFragments = new ArrayList<>();

    @Override
    protected int attachLayoutRes() {
        return R.layout.common_activity_tablayout;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {
        getToolbarTitle().setText(R.string.person_coupons);
        initViewPager();
    }

    @Override
    protected void updateViews() {

    }


    private void initViewPager() {
        addTabTitle();
        addTabFragment();
        mFragmentAdapter = new CommonTabLayoutAdapter(getSupportFragmentManager(), mFragments, titles);
//        //给ViewPager设置适配器
        viewPager.setAdapter(mFragmentAdapter);
        viewPager.setOffscreenPageLimit(titles.size());
        //将TabLayout和ViewPager关联起来。
        mTabLayout.setupWithViewPager(viewPager);

    }

    private void addTabTitle() {
        titles = new ArrayList<>();
        titles.add("可使用");
        titles.add("已使用");
        titles.add("已过期");
        for (int i = 0; i < titles.size(); i++) {
            mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(i)));
        }

    }


    private void addTabFragment() {
        AvailableFragment availableFragment = new AvailableFragment();
        UsedFragment usedFragment = new UsedFragment();
        OverduFragment overduFragment = new OverduFragment();
        mFragments.add(availableFragment);
        mFragments.add(usedFragment);
        mFragments.add(overduFragment);
    }


}
